# $Id$
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Massimiliano Torromeo < massimiliano DOT torromeo AT gmail DOT com >

pkgbase=python-beaker
pkgname=('python-beaker' 'python2-beaker')
pkgver=1.8.1
pkgrel=2
arch=('any')
license=('custom')
pkgdesc="Caching and sessions WSGI middleware for use with web applications and stand-alone Python scripts and applications"
url="http://beaker.groovie.org/"
makedepends=('python-setuptools' 'python2-setuptools' 'git')
checkdepends=('python-nose' 'python2-nose' 'python-mock' 'python2-mock' 'python-sqlalchemy' 'python2-sqlalchemy'
              'python-crypto' 'python2-crypto' 'python-coverage' 'python2-coverage' 'python-webtest' 'python2-webtest'
              'python-beautifulsoup4' 'python2-beautifulsoup4')
source=("git+https://github.com/bbangert/beaker.git#tag=$pkgver")
md5sums=('SKIP')

prepare() {
    cp -a beaker{,-py2}

    sed -i "s#/usr/bin/python#/usr/bin/python3#" beaker/beaker/crypto/pbkdf2.py
    sed -i "s#/usr/bin/python#/usr/bin/python2#" beaker-py2/beaker/crypto/pbkdf2.py
}

build() {
    cd "$srcdir"/beaker
    python3 setup.py build

    cd "$srcdir"/beaker-py2
    python2 setup.py build
}

check() {
    cd "$srcdir"/beaker
    mkdir tests_py3
    2to3 -w -n -o tests_py3 tests/*.py
    PYTHONPATH="$PWD/build/lib:$PYTHONPATH" nosetests3 --py3where=tests_py3

    cd "$srcdir"/beaker-py2
    PYTHONPATH="$PWD/build/lib:$PYTHONPATH" nosetests2
}

package_python-beaker() {
    depends=('python')

    cd beaker
    python3 setup.py install --root="$pkgdir" --optimize=1
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/python-beaker/LICENSE
}

package_python2-beaker() {
    depends=('python2')

    cd beaker-py2
    python2 setup.py install --root="$pkgdir" --optimize=1
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/python2-beaker/LICENSE
}
